package com.focusai.efairy.ui.adapter;

import android.content.Context;
import android.view.View;
import android.widget.CheckBox;

import com.focusai.efairy.R;
import com.focusai.efairy.ui.adapter.base.BaseRecyclerAdapter;
import com.focusai.efairy.ui.adapter.base.BaseRecyclerViewHolder;
import com.focusai.efairy.ui.adapter.msg.DeviceConversation;
import com.focusai.efairy.utils.DateUtils;

/**
 * Created by luo_guangwen on 2017/8/13.
 */

public class NewsAdapter extends BaseRecyclerAdapter<DeviceConversation> {
    private boolean isEdit = false;
    public NewsAdapter(Context context) {
        super(context);
    }

    @Override
    protected int getItemLayoutId() {
        return R.layout.item_dev_msg;
    }

    @Override
    protected void onBindBaseRecyclerViewHolder(BaseRecyclerViewHolder holder, int position) {
        final DeviceConversation item = mList.get(position);
        holder.setText(R.id.text_dev_name, item.msgItem.efairydevice_name);
        holder.setText(R.id.text_dev_state, DateUtils.getFormatDatePattern(item.conversation.getSentTime()));
        if (item.conversation.getUnreadMessageCount() > 0) {
            holder.getView(R.id.tv_unread_msg_tip).setVisibility(View.VISIBLE);
        } else {
            holder.getView(R.id.tv_unread_msg_tip).setVisibility(View.GONE);
        }

        holder.setText(R.id.text_dev_status, item.msgItem.get_content());
        CheckBox checkSelected = (CheckBox) holder.getView(R.id.iv_selected);
        checkSelected.setOnClickListener(null);
        if (isEdit) {
            checkSelected.setVisibility(View.VISIBLE);
            if (item.isSeleted){
                checkSelected.setChecked(true);
            }else {
                checkSelected.setChecked(false);
            }
        } else {
            checkSelected.setVisibility(View.GONE);
        }
    }

    public void setEdit(boolean edit) {
        isEdit = edit;
    }
}
